/**
 * 根据通过的百分比将6个字符的HEX颜色变浅
 * @param {string} color 
 * @param {number} amount 
 * @returns {string}
 */
export function lighten(color, amount) {
    color = color.indexOf('#') >= 0 ? color.substring(1, color.length) : color;
    amount = Math.trunc((255 * amount) / 100);
    return `#${addLight(color.substring(0, 2), amount)}${addLight(
        color.substring(2, 4),
        amount
    )}${addLight(color.substring(4, 6), amount)}`;
}

/**
 * 将通过的百分比求和为HEX颜色的R， G或B
 * @param {string} color 
 * @param {number} amount 
 * @returns {string} 
 */
function addLight(color, amount) {
    const cc = parseInt(color, 16) + amount;
    const c = cc > 255 ? 255 : cc;
    return c.toString(16).length > 1 ? c.toString(16) : `0${c.toString(16)}`;
}

/**
 * 生成6位随机数
 * @returns {number}
 */
export function generateRandomSixDigitNumber() {
    return Math.floor(100000 + Math.random() * 900000);
}

/**
 * 打开新页面
 * @param {*} url 
 */
export function goToOtherPage(url) {
    window.open(url, '_blank');
}
